// pages/canteen/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menu: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:function(option) {
    let that = this

    if(!wx.getStorageSync('login')) {
      wx.redirectTo({
        url: '/pages/canteen/login/login',
      })
    }

    wx.cloud.callFunction({
      name: 'lu',
      data: {
        action: 'findcanteen',
        canteen_id: wx.getStorageSync('canteen_id')
      },
      success(res) {
        let canteen = res.result.data[0].canteen_name
        that.setData({
          canteen
        })
        console.log("云函数获取数据成功",res)
      },
      fail(res) {
        console.log("函数获取数据失败",res)
      }
    })

    wx.cloud.callFunction({
      name: 'lu',
      data: {
        action: 'findwindow',
        window_id: wx.getStorageSync('window_id')
      },
      success(res) {
        let window = res.result.data[0].window_name
        that.setData({
          window
        })
        console.log("云函数获取数据成功",res)
      },
      fail(res) {
        console.log("函数获取数据失败",res)
      }
    })

  },
  onShow: function () {
    let that = this
    wx.cloud.callFunction({
      name: 'lu',
      data: {
        action: 'meal',
        canteen_id: wx.getStorageSync('canteen_id'),
        window_id : wx.getStorageSync('window_id')
      },
      success(res) {
        let meal = res.result.data
        that.setData({
          menu: meal
        })
        console.log("云函数获取数据成功",meal)
      },
      fail(res) {
        console.log("函数获取数据失败",res)
      }
    })
  },
  goUploadMenu: function() {
    console.log("跳转到上传饭菜的页面")
    wx.navigateTo({
      url: '../uploadfool/uploadfool',
    })
  },

  goRefreshMenu: function() {
    console.log("饭菜管理了..")
    wx.navigateTo({
      url: '/pages/canteen/manage/manage',
    })
  },

  goOrderMenu: function() {
    wx.navigateTo({
      url: '/pages/canteen/record/record',
    })
  }
})